/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.osdtsystem.dataset;

import org.osdtsystem.hierarchy.HClass;
import org.osdtsystem.hierarchy.Hierarchy;

/**
 * A composite view consisting of several subviews.
 * @param <H> the type of hierarchy classes in the view
 * @author Martin Haulrich and Matthias Buch-Kromann
 */
public class CompositeHierarchyView<H extends HClass> extends CompositeView implements HierarchyView<H> {
    Hierarchy<H> hierarchy;
    // HierarchyView<?>[] subviews;

    public CompositeHierarchyView(Hierarchy<H> hierarchy, HierarchyView<?>... subviews) {
        super(subviews);
        this.hierarchy = hierarchy;
    }

    @Override
    public Hierarchy<H> hierarchy() {
        return hierarchy;
    }

    @SuppressWarnings("unchecked")
    @Override
    public <H2 extends HClass> HierarchyView<H2> subview(Class<H2> hclassType, int i) {
        HierarchyView<?> subview = (HierarchyView<?>) subview(i);
        if (subview.hierarchy().hclassType().equals(hclassType))
            return (HierarchyView<H2>) subview;
        else
            throw new IllegalArgumentException("Subview "
                    + i + " in view  " + this + ": expected hclass type "
                    + hclassType + " but found " + subview.hierarchy().hclassType());
    }
}
